﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manager.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="B2B.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>ProductUpdatePostBuyRequest</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
      <script type="text/javascript">
          function loadDanhMuc(maLinhVuc) {
           
              if (maLinhVuc != 0) {
                  $.getJSON("/Home/DanhSachDanhMuc?id=" + maLinhVuc,
                   function (data) {
                       document.getElementById("checkCategory").innerText = "";
                       var s = '';
                       s += "<select id='MaDanhMuc' name='maDanhMuc'>";
                       for (i = 0 ; i < data.length; i++) {
                           s += "<option value='" + data[i].MaDanhMuc + "'>" + data[i].TenDanhMuc + "</option>";
                       }
                       s += "</select>";
                       $("#divDanhMuc").html(s);
                   });
              }
              else {
                  document.getElementById("checkCategory").innerText = "Please select a item in category";
              }
          }



          function CheckAndSend() {


              var quantity = document.getElementById("SoLuongCanMua");
              var productname = document.getElementById("TenSanPham");
              var category = document.getElementById("selProductCategory");
              var detail = document.getElementById("ChiTiet");
              var file = document.getElementById("HinhAnh");
              if (productname.value == "") {
                  //  document.getElementById("checkProductName").innerHtml = "Please enter product name";
                  $("#checkProductName").html("*Please enter product name");
                  productname.focus();
                  return false;
              }
              else {
                  $("#checkProductName").html("");
              }

              if (category.value == 0) {
                  $("#checkCategory").html("*Please select a item in category");
                  category.focus();
                  return false;
              }
              else {
                  $("#checkCategory").html("");
              }

              if (quantity.value == "") {
                  $("#CheckQuantity").html("Please enter estimated order quantity");
                  quantity.focus();
                  return false;
              }
              else {
                  $("#CheckQuantity").html("");
              }

              /*  var json = {
                    TenSanPham: productname.value,
                    MaDanhMuc: category.value,
                    SoLuongCanMua: quantity.value,
                    HinhAnh: file.files[0].name,
                    FileUpload: file.value,
                    MaThanhVien: 1,
                    ChiTiet: detail.value,
                    TinhTrang: false
                };
                $.ajax({
                    url: '/Product/ProductPostBuy',
                    type: 'POST',
                    contentType: 'application/json',
                    dataType: 'json',
                    data: JSON.stringify(json),
                    success: function (response) {
                        alert(response);
                    }
                });*/

          }

          function onlyNumbers(e) {

              var keyword = null;
              if (window.event) {
                  keyword = window.event.keyCode;
              } else {
                  keyword = e.which; //NON IE;
              }

              if (keyword < 48 || keyword > 57) {
                  if (keyword == 48 || keyword == 127 || keyword == 8) {
                      return;
                  }
                  $("#CheckQuantity").html("You have to enter number");
                  return false;
              }
              $("#CheckQuantity").html("");
          }

          function changeImage() {
              var src = $("#HinhAnh").val();
              $("#imgSPM").attr("src", src);
              alert(src);
          }
    </script>
   
        <h6> Management -> Product Post Buy -> Update</h6>
    <!--Bắt đầu post a buying request-->
    <div align="left">            
        <div align="center">
            <%
                PostBuyRequest spm = (PostBuyRequest) ViewData["SPMua"];
                string hinhAnh = spm.HinhAnh.ToString();
                string url = "../../Images/Product/" + hinhAnh;
            %>
            <!--Bắt đầu bảng post a buying Request-->
            <form onsubmit="return CheckAndSend()" method="post" action="/Manage/UpdatePostBuy" enctype="multipart/form-data">
                <table border="0">
                    <tr>
                        <th align="center" colspan="2"><div><h4>Tell The Supplier What You Want</h4></div></th>
                    </tr>
                    <tr>
                        <th>Product Name:</th>
                        <td >
                            <input type="text" id="TenSanPham" name="tenSanPham" value="<%=spm.TenSanPham %>" />
                            <input type="hidden" name="maSanPhamMua" value="<%=spm.MaSanPhamMua %>"
                            <div id="checkProductName" style="color: red"></div>
                        </td>
                    </tr>

                    <tr>
                        <th style="width: 200px; height: 62px;">Product Category: </th>
                        <!--Tu viet group box bang javascript de chon muc mua hang-->
                    
                    
                        <td style=" height: 62px; width:600px">
                                <select ID="selProductCategory">
                                     <option value="0">--Please select category--</option>
                                    <%foreach(var lv in (ArrayList)ViewData["linhvuc"]) 
                                      {%>                             
                                       
                                        <%if( ((LinhVuc)lv).MaLinhVuc == spm.MaLinhVuc){%>
                                            <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')"  selected='selected' value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                        <%}
                                          else{ %>
                                             <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')" value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                        <%} %>
                                    <%}%>
                                </select>
                                <div id="divDanhMuc">
                                   <select name="maDanhMuc">
                                       <%foreach(var dm in (List<DanhMuc>)ViewData["DM_SPM"])
                                         { %>
                                       <%if(dm.MaDanhMuc == spm.MaDanhMuc ){%>
                                       <option value="<%=dm.MaDanhMuc %>" selected="selected"> <%=dm.TenDanhMuc %></option>
                                       <%} %>
                                       <%else{ %>
                                       <option value="<%=dm.MaDanhMuc %>"> <%=dm.TenDanhMuc %></option>
                                       <%} %>
                                       <%} %>
                                   </select>
                                </div>
                                    <div id="checkCategory" style="color: red"></div>
                                </td>
                      
                    </tr>

                     <tr>
                        <th style="height: 91px">Product Detailed Specification: </th>
                   
                        <td style="height: 91px"><textarea cols="50" rows="5" class="ckeditor" id="editor1" name="chiTiet"><%=spm.ChiTiet %></textarea></td>
                   
                       
                    </tr>

                    <tr>
                        <th style="height: 35px">Relevant Files to the Request: </th>
                        <td style="height: 35px">
                            <img src="<%=url %>" name="hinhAnh" id="imgSPM" /><br />
                              <input id="HinhAnh" onchange="changeImage();" name="fileUpload" style="width: 81%; height: 30px; margin-top: 5px;" type="file" />                     
                             <input type="hidden" name="maThanhVien" value="<%=Session["maTV"].ToString() %>" />
                            <br />
                        </td>
                       
                    </tr>

                    <tr>
                        <th>Estimated Order Quantity: </th>
                        <td>
                            <table>
                                <tr>
                                    <td style="height: 42px"><input type="number" id="SoLuongCanMua" onkeypress="return onlyNumbers(event)" value="<%=spm.SoLuongCanMua %>" name="soLuongCanMua" /></td>
                                </tr>
                            </table>
                             <div ID="CheckQuantity" style="color: red"></div>
                        </td>
                     
                           
                    </tr>
                  
                   <tr>
                      <td></td>
                      <td>
                          <input type="submit" value="Update" id="send"/>
                          <input type="button" value="Reset" id="Reset"/>
                      </td>
                       
                   </tr>

                </table>
            </form>
            <!--Kết thúc bảng post a buying Request-->
        </div>
    </div>
    <!--Kết thúc post a buying request-->

</asp:Content>
